package conversions

import (
	"hi-jvm/instructions/base"
	"hi-jvm/rtda"
)

/*
类型转换指令共有15条。
按照被转换变量的类型，类型
 */

// Convert double to float
type D2F struct{ base.NoOperandsInstruction }
// Convert double to int
type D2I struct{ base.NoOperandsInstruction }
// Convert double to long
type D2L struct{ base.NoOperandsInstruction }

func (self *D2F) Execute(frame *rtda.Frame) {
	stack := frame.OperandStack
	d := stack.PopDouble()
	f := float32(d)
	stack.PushFloat(f)
}

func (self *D2I) Execute(frame *rtda.Frame) {
	stack := frame.OperandStack
	d := stack.PopDouble()
	i := int32(d)
	stack.PushInt(i)
}

func (self *D2L) Execute(frame *rtda.Frame) {
	stack := frame.OperandStack
	d := stack.PopDouble()
	l := int64(d)
	stack.PushLong(l)
}
